const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('sys_region', {
    code: {
      type: DataTypes.STRING(12),
      allowNull: false,
      primaryKey: true,
      comment: "区划编号"
    },
    parentCode: {
      type: DataTypes.STRING(12),
      allowNull: true,
      comment: "父区划编号",
      field: 'parent_code'
    },
    ancestors: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "祖区划编号"
    },
    name: {
      type: DataTypes.STRING(32),
      allowNull: true,
      comment: "区划名称"
    },
    provinceCode: {
      type: DataTypes.STRING(12),
      allowNull: true,
      comment: "省级区划编号",
      field: 'province_code'
    },
    provinceName: {
      type: DataTypes.STRING(32),
      allowNull: true,
      comment: "省级名称",
      field: 'province_name'
    },
    cityCode: {
      type: DataTypes.STRING(12),
      allowNull: true,
      comment: "市级区划编号",
      field: 'city_code'
    },
    cityName: {
      type: DataTypes.STRING(32),
      allowNull: true,
      comment: "市级名称",
      field: 'city_name'
    },
    districtCode: {
      type: DataTypes.STRING(12),
      allowNull: true,
      comment: "区级区划编号",
      field: 'district_code'
    },
    districtName: {
      type: DataTypes.STRING(32),
      allowNull: true,
      comment: "区级名称",
      field: 'district_name'
    },
    townCode: {
      type: DataTypes.STRING(12),
      allowNull: true,
      comment: "镇级区划编号",
      field: 'town_code'
    },
    townName: {
      type: DataTypes.STRING(32),
      allowNull: true,
      comment: "镇级名称",
      field: 'town_name'
    },
    villageCode: {
      type: DataTypes.STRING(12),
      allowNull: true,
      comment: "村级区划编号",
      field: 'village_code'
    },
    villageName: {
      type: DataTypes.STRING(32),
      allowNull: true,
      comment: "村级名称",
      field: 'village_name'
    },
    regionLevel: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "层级",
      field: 'region_level'
    },
    sort: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "排序"
    },
    remark: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "备注"
    }
  }, {
    sequelize,
    tableName: 'sys_region',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "code" },
        ]
      },
    ]
  });
};
